<template>
  <!-- 招聘信息显示 -->
  <div class="buttons">
    <el-button-group
      v-for="resume in resume"
      :key="resume.name"
      style="margin-bottom: 10px"
    >
      <el-button
        type="primary"
        size="large"
        @click="checkPersonInfo(resume)"
        color="#7f96ab"
        style="color: white"
        >{{ resume.name }}---{{ resume.recruit }}</el-button
      >
      <el-button type="primary" size="large" @click="failedResume(resume)">
        <el-icon class="el-icon-close"><Close /></el-icon>
      </el-button>
      <el-button type="primary" size="large" @click="passedResume(resume)">
        <el-icon class="el-icon-check"><Check /></el-icon>
      </el-button>
      <el-tag
        :type="
          resume.fflag === 1
            ? 'success'
            : resume.fflag === 2
              ? 'danger'
              : 'info'
        "
      >
        {{
          resume.fflag === 1 ? '通过' : resume.fflag === 2 ? '未通过' : '待定'
        }}
      </el-tag>
    </el-button-group>
  </div>

  <!-- 简历展示 -->
  <!-- <el-dialog
    v-model:visible="visibleDrawer"
    width="50%"
    class="resume-container"
    > -->
  <el-dialog
    v-model="visibleDrawer"
    :before-close="beforeClose"
    :title="title"
    width="500"
  >
    <el-card class="resume-card" shadow="hover">
      <template v-slot:header>
        <div class="clearfix">
          <div class="header-left">
            <span class="name">{{ cardInfo.name }}</span>
            <div class="pinyin">{{ pinyin(cardInfo.name) }}</div>
          </div>
          <div class="header-right">
            <div class="dots"></div>
            <div class="position-info">
              <span class="position-item">{{ cardInfo.department }}</span>
              <span class="position-item">{{ cardInfo.position }}</span>
            </div>
          </div>
        </div>
      </template>
      <el-form label-width="80px" class="resume-content">
        <el-form-item label="名称">
          <span>{{ cardInfo.name }}</span>
        </el-form-item>
        <el-form-item label="电话">
          <span>{{ cardInfo.phone }}</span>
        </el-form-item>
        <el-form-item label="邮箱">
          <span>{{ cardInfo.email }}</span>
        </el-form-item>
        <el-form-item label="部门">
          <span>{{ cardInfo.department }}</span>
        </el-form-item>
        <el-form-item label="岗位">
          <span>{{ cardInfo.position }}</span>
        </el-form-item>
        <el-form-item label="详情">
          <span>{{ cardInfo.detail }}</span>
        </el-form-item>
      </el-form>
      <!-- <el-button
        class="close-btn"
        type="text"
        icon="el-icon-close"
        @click="closeCard"
      ></el-button> -->
    </el-card>
  </el-dialog>
</template>

<script setup>
import { reactive, defineProps, ref, watchEffect } from 'vue'
import { Close, Check } from '@element-plus/icons-vue'
import { pinyin } from 'pinyin-pro'
import { resumeEdit } from '../../../api/hire'
const cardInfo = reactive({})

// 定义接收父级传递的 props
const props = defineProps({
  dataCheck: Array,
  dataAll: Array
  // visibleDrawerHire: Boolean
})
// 接受传过来的简历数据--分页的数据
const resume = ref([])
//简历发布显示
const visibleDrawer = ref(false)
//所有数据
const dataAll = props.dataAll
watchEffect(() => {
  // 在 props.dataCheck 变化时被调用
  resume.value = props.dataCheck
  // visibleDrawer.value = props.visibleDrawerHire
  // console.log(recruit, '简历')

  if (dataAll.value) {
    resume.value = dataAll.value.slice(0, 5)
  }
})

//点击查看简历卡片信息
const checkPersonInfo = (resume) => {
  //打开弹窗
  visibleDrawer.value = true
  Object.assign(cardInfo, resume)
  console.log(cardInfo, 'kap resume')
}
// 通过简历筛选函数
const passedResume = async (resume) => {
  resume.fflag = 1
  const res = await resumeEdit(resume)
  if (res.code === 200) {
    ElMessage.success('简历通过')
  }
}

//未通过简历筛选函数
const failedResume = async (resume) => {
  resume.fflag = 2
  const res = await resumeEdit(resume)
  if (res.code === 200) {
    ElMessage.success('简历未通过')
  }
}

const beforeClose = () => {
  //关闭弹窗
  visibleDrawer.value = false
  //清空当前的form
  // formRef.value.resetFields()
}
</script>

<style lang="less" scoped>
.editor {
  width: 100%;
  :deep(.ql-editor) {
    min-height: 200px;
  }
}
.buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  //   width: 100%;

  .el-button-group {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .el-button--primary {
    width: 80%;
    margin: 5px 0; /* 按钮间距 */
  }
  /* 第一个按钮占75% */
  .el-button-group > .el-button--primary:first-child {
    flex: 10; /* 75% */
  }

  /* 其他两个按钮平分剩余的25% */
  .el-button-group > .el-button--primary:not(:first-child) {
    flex: 1; /* 25% / 2 = 12.5% */
  }

  .el-tag {
    // flex: 1;
    margin: 1px; /* 移除标签与按钮之间的间距 */
    height: 40px; /* 假设按钮的高度是40px，可以根据实际情况调整 */
    line-height: 40px; /* 使文本垂直居中 */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
  }
  .el-button-group > :not(:first-child):first-of-type {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  .el-button-group > :not(:first-child):last-of-type {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  .el-button-group > :first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  .el-button-group > :last-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
}

//卡片显示

.resume-container {
  max-width: 800px;
  margin: 20px auto;
}

.resume-card {
  border-radius: 10px;
  color: #333;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.resume-card:hover {
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.clearfix:before,
.clearfix:after {
  content: ' ';
  display: table;
}

.clearfix:after {
  clear: both;
}

.header-left {
  float: left;
}

.header-right {
  float: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.name {
  font-size: 24px;
  color: #a5c4de;
}

.pinyin {
  font-size: 14px;
  color: #a5c4de;
  background-color: #fff;
  border: 1px solid #a5c4de;
  padding: 2px 5px;
  border-radius: 4px;
  margin-top: 5px;
}

.dots {
  display: inline-block;
  width: 1em;
  height: 1em;
  background: url('data:image/svg+xml;utf8,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><circle  cx="20" cy="20" r="5" fill="%23ad1457"/><circle cx="50" cy="20" r="5" fill="%23ad1457"/><circle cx="80" cy="20" r="5" fill="%23ad1457"/></svg>')
    no-repeat center;
  background-size: contain;
  margin-bottom: 5px; /* 调整点与职位信息的间距 */
}

.position-info {
  display: flex;
  align-items: center;
}

.position-item {
  margin-right: 10px;
  padding: 6px;
  background-color: #a5c4de; /* 浅灰色背景 */
  border-radius: 4px;
  color: white;
}

.resume-content {
  padding: 20px;
}

.resume-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #ad1457; /* 深粉色 */
  margin-right: 10px;
}

.content {
  font-weight: bold;
  color: #333;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: #999;
  font-size: 18px;
  z-index: 10; /* 确保按钮在其他元素之上 */
}

.close-btn:hover {
  color: #666;
}

.dots {
  display: inline-block;
  width: 1em;
  height: 1em;
  background: url('data:image/svg+xml;utf8,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><circle  cx="20" cy="20" r="5" fill="%23ad1457"/><circle cx="50" cy="20" r="5" fill="%23ad1457"/><circle cx="80" cy="20" r="5" fill="%23ad1457"/></svg>')
    no-repeat center;
  background-size: contain;
  margin-bottom: 5px; /* 调整点与职位信息的间距 */
}
</style>
